# -*-coding:utf-8-*-
"""
@project: SM
@Time: 2024-08-01 19:56
@Author: Loneliness_Burial
@File: common.py
@Motto: 深情不改必坠死海
@software: pycharm
@version: python 3.7
"""

import hashlib
import logging.config
from conf import settings

"""
公共方法
"""


# 登录认证装饰器
def login_auth(func):
    def wrapper(*args, **kwargs):
        from core import src
        if src.logged_user:
            res = func(*args, **kwargs)
            return res
        else:
            print('\n未登录账号! ')
            src.login()

    return wrapper


# 密码加密
def pwd_to_sha256(password):
    sha = hashlib.sha256()
    sha.update(password.encode('utf-8'))
    sha.update('且随疾风前行'.encode('gbk'))
    return sha.hexdigest()


# 日志记录功能
def get_logger(logger_name):
    logging.config.dictConfig(settings.LOGGING_DIC)
    logger = logging.getLogger(logger_name)
    return logger
